package LessonWork;

import java.util.Scanner;

public class MyJosephus {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        //获取人数数量
        int total = scanner.nextInt();
        //获取开始的位置
        int start = scanner.nextInt();
        //获取每个distance个人
        int distance = scanner.nextInt();

        Node<Integer> head = new Node<>();
        Node<Integer> cur;

        //为链表赋值
        cur = head;
        for (int i=1;i<=total;i++){
            cur.next=new Node<>(i,null);
            cur = cur.next;
        }


        //将有数据的部分首尾相连
        cur.next = head.next;

        //将目前指针重新移动回到第一个节点
        cur=head.next;
        //将指针最开始移动到 start 位置
        for (int i=1;i<start;i++){
            cur = cur.next;
        }

        System.out.println(cur.data);

        //创建一个新的指针用于循环
        Node<Integer> location = cur;
        while (location.next!=location){
            for (int i=1;i<distance-1;i++){
                location=location.next;
            }
            System.out.println(location.next.data);
            location.next=location.next.next;
            location=location.next;
        }

        System.out.println("最后存活下来的人是"+location.data);
    }
}
